
import os
from kubernetes import client, config
from functools import lru_cache
from setting import config

__all__ = ["init_k8s"]


@lru_cache
def init_k8s() -> None:
    k8s_api = config.K8S_API
    k8s_token = config.K8S_TOKEN
    app_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    ca_path = os.path.join(app_root, config.K8S_CA_PATH)

    configuration = client.Configuration()
    configuration.host = k8s_api
    configuration.api_key = {"authorization": "Bearer " + k8s_token}

    if config.K8S_CA_PATH:
        configuration.verify_ssl = True
        configuration.ssl_ca_cert = ca_path
    else:
        configuration.verify_ssl = False
    client.Configuration.set_default(configuration)

    return None





def main():
    init_k8s()
    print("aaa")


if __name__ == "__main__":
    main()
